package br.com.intelsys.entityutil.spring;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import br.com.intelsys.basics.dao.hiber.DaoHiber;
import br.com.intelsys.entityutil.entity.dic.locale.City;
import br.com.intelsys.entityutil.entity.dic.locale.CityHiber;
import br.com.intelsys.entityutil.entity.dic.locale.Country;
import br.com.intelsys.entityutil.entity.dic.locale.CountryHiber;
import br.com.intelsys.entityutil.entity.dic.locale.State;
import br.com.intelsys.entityutil.entity.dic.locale.StateHiber;

@Component
@Scope("request")
public class LocaleDao extends DaoHiber {

	@Autowired
	public LocaleDao(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	public List<City> getCityList(int codState) {
		return getQueryManager().find("br.com.intelsys.entityutil.entity.dic.locale.CityHiber.getCityListFromState")
				.param("codState", codState).getList();
	}

	public Country getCountry(int codCountry) {
		return (Country) getQueryManager().get(CountryHiber.class, Integer.valueOf(codCountry));
	}

	public State getState(int codState) {
		return (State) getQueryManager().get(StateHiber.class, Integer.valueOf(codState));
	}

	public List<State> getStateList(int codCountry) {
		return getQueryManager().find("br.com.intelsys.entityutil.entity.dic.locale.StateHiber.getStateListFromCountry")
				.param("codCountry", codCountry).getList();
	}

	public State getState(int codCountry, String acronym) {
		return (State) getQueryManager().find("br.com.intelsys.entityutil.entity.dic.locale.StateHiber.getStateByAcronym")
				.param("codCountry", codCountry).param("acronym", acronym).getUniqueValue();
	}

	public City getCity(int codState, String addr) {
		return (City) getQueryManager().find("br.com.intelsys.entityutil.entity.dic.locale.CityHiber.getCityByAddr")
				.param("codState", codState).param("addr", addr).getUniqueValue();
	}

	public City getCity(int codCity) {
		return (City) getQueryManager().get(CityHiber.class, Integer.valueOf(codCity));
	}

}
